<template>
    <z-paging :use-virtual-list="true" :auto-show-back-to-top="true" :loading-full-fixed="true"
        :auto-show-system-loading="true" ref="pagingRef" @query="queryListFn">
        <template #cell="{ item, index }">
            <view class="cards mx-32 mt-30">
                <view class="df ac" @click="toggleItem(item, index)">
                    <uv-tags :text="item.Town" plain size="mini"></uv-tags>
                    <view style="margin-left: auto;margin-right: 10rpx;">{{ item.Tbr }}</view>
                    <uv-icon :name="item.toggle ? 'arrow-up' : 'arrow-down'" size="32rpx"></uv-icon>
                </view>
                <view v-if="item.toggle">
                    <view class="card-content">{{ item.Remark }}</view>
                    <view class="card-object-item fs-28">填表人：{{ item.Tbr }}</view>
                    <view class="card-object-item fs-28">发生时间：{{ dayjs(item.CreateTime).format('YYYY-MM-DD HH:mm:ss') }}
                    </view>
                    <view class="card-footer df jsa">
                        <uv-button type="error" :disabled="!!item.ApprovalRemark" size="mini" @click="toReport(item.Id)"
                            v-if="optype == 1">{{
                                item.ApprovalRemark == null ? '审批' : '已审批' }}</uv-button>
                        <uv-button type="primary" size="mini" @click="viewItem(item.Id)">查看</uv-button>
                        <!-- <uv-button type="error" size="mini" @click="deleteItem(item.Id)">删除</uv-button> -->
                    </view>
                </view>

            </view>
        </template>
    </z-paging>
</template>

<script lang="ts" setup>
import { GetZqsbGetPage_API, ZqsbDel_API } from '@/server/home'
import { SYSFORMOPERTYPE } from '@/utils/enum'
import dayjs from 'dayjs'
const optype = ref(0)
onLoad((e) => {
    optype.value = e.optype || 0
})
const pagingRef = ref()
/**
 * 获取数据
 * @param pageNo 当前页
 * @param pageSize 条数
 */
const queryListFn = async (pageNo: any, pageSize: any) => {
    const params = {
        pageNumber: pageNo,
        pageSize: pageSize,
        // AdminCode: store.userInfo.AdminCode,
    }
    try {
        const res = await GetZqsbGetPage_API(params)
        if (res.IsSuccess) {
            pagingRef.value.complete(res.Data.Data.map(el => ({ ...el, toggle: false })))

        }
    } catch (error) {
        pagingRef.value.complete(false)
    }
}

const toggleItem = (item: any, index: number) => {
    item.toggle = !item.toggle;
}
const viewItem = (id) => {
    uni.navigateTo({
        url: `/pages/home/disasterReportSimple-look?optype=${SYSFORMOPERTYPE.View}&id=${id}`
    });
}

const toReport = (id) => {
    uni.navigateTo({
        url: `/pages/home/disasterReportSimple-look?optype=${SYSFORMOPERTYPE.pass}&id=${id}`
    })
}
const deleteItem = (id) => {
    uni.showModal({
        title: '提示',
        content: '是否确认删除？',
        async success(res) {
            if (res.confirm) {
                const res = await ZqsbDel_API(id)
                if (res.IsSuccess) {
                    uni.$uv.toast('删除成功')
                }
                pagingRef.value.refresh()
            }
            else {

            }
        }
    })
}
</script>

<style lang="scss" scoped>
.card-content {
    font-size: 32rpx;
    color: #272727;
}

.card-object-item {
    color: #948b8b;
}
</style>
